/**
 * Created by 01 on 2017/6/27.
 */
function formatDate(format, newDate) {
  newDate = newDate ? new Date(newDate) : new Date();
  let k, reg,
    o = {
      'y+': newDate.getFullYear(), //year
      'M+': newDate.getMonth() + 1, //month
      'd+': newDate.getDate(), //day
      'h+': newDate.getHours(), //hour
      'm+': newDate.getMinutes(), //minute
      's+': newDate.getSeconds(), //second
    };
  for (k in o) {
    reg = new RegExp('(' + k + ')');
    if (reg.test(format)) format = format.replace(reg, o[k] < 10 ? ('0' + o[k]) : o[k]);
  }
  return format;
}

export {formatDate};